package com.xbongbong.saas.enums.dictionary;

import com.xbongbong.i18n.util.I18nMessageUtil;
import lombok.Getter;

/**
 * 优惠券状态
 *
 * @author jyh
 * @version v1.0
 * @since v1.0
 */
@Getter
public enum CouponStatusEnum {
    /**
     * 已领取
     */
    RECEIVED(0, "enum.couponStatus.name.received", "received"),
    /**
     * 已使用
     */
    USED(1, "enum.couponStatus.name.used", "used"),
    /**
     * 已过期
     */
    EXPIRED(2, "enum.couponStatus.name.expired", "expired"),



    ;

    private Integer code;
    private String name;
    private String attr;

    CouponStatusEnum(Integer code, String name, String attr) {
        this.code = code;
        this.name = name;
        this.attr = attr;
    }

    /**
     * 通过枚举 code 获得枚举
     *
     * @param code 枚举Code
     *
     * @return TransferStatusEnum
     */
    public static CouponStatusEnum getByCode(Integer code) {
        for (CouponStatusEnum cacheCode : values()) {
            if (code.equals(cacheCode.getCode())) {
                return cacheCode;
            }
        }
        return null;
    }

    public String getName() {
        return I18nMessageUtil.getMessage(name);
    }
}
